/**
 * Created by WT-SUN on 2017/5/8.
 */

$(function () {
    $('#planTb').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/train/plan/TrTable.shtml',
        queryParams: {
            sort: 'addTime',
            order: 'desc'
        },
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'name', title: '培训班名称', width: 150},
            {field: 'proTypeIdName', title: '专业类别', width: 100},
            {field: 'planTypeIdName', title: '计划分类', width: 100},
            {field: 'trainLevelIdName', title: '培训级别', width: 100},
            {field: 'planStartMonth', title: '计划开班月份', width: 120},
            {field: 'planTrainPerson', title: '计划培训人数', width: 120},
            {field: 'planTrainHour', title: '计划培训学时', width: 120},
            {
                field: 'isExternal', title: '是否外部培训', width: 120, formatter: function (value, row, index) {
                return row.isExternal == '0' ? '不是' : '是';
            }
            },
            {field: 'hostDeptNamea', title: '主办单位', width: 100, formatter: function (value, row, index) {
                return row.isExternal == '0' ? row.hostDeptIdName : row.hostDeptName;
            }},
            {field: 'trainDeptId', title: '培训机构', width: 100},
            {
                field: 'hasCertificate', title: '是否取证', width: 100, formatter: function (value, row, index) {
                return row.hasCertificate == '0' ? '不是' : '是';
            }
            },
            {field: 'realName', title: '登记人', width: 100}
        ]]
    });

    $('#btn_save').on("click", function () {
        var $selected = $('#planTb').datagrid('getSelections');
        if($selected.length==0){
            layer.alert("请选择培训计划！");
            return;
        }
        WindowManager.closeLayer({
            returnValue: $selected
        });
    });

});

/**
 * 重新加载表格
 */
function reLoadData() {
    $('#planTb').datagrid('clearSelections');
    var queryParams = $('#queryForm1').serializeJson();
    queryParams["sort"] = 'addTime';
    queryParams["order"] = 'desc';
    $('#planTb').datagrid('options').queryParams = queryParams;
    $("#planTb").datagrid('reload', ROOT_PATH + '/train/plan/TrTable.shtml');
}


